/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgMapUiEntity
    {
        private readonly Dictionary<int, CfgMapUiEntity> _dataMap;
        private readonly List<CfgMapUiEntity> _dataList;

        /// <summary>
        /// 玩家Cid
        /// </summary>
        public int PlayerCid { get; private set; }
        /// <summary>
        /// 任务目标点Cid
        /// </summary>
        public int QuestTargetCid { get; private set; }
        /// <summary>
        /// 任务区域Cid
        /// </summary>
        public int QuestAreaCid { get; private set; }
        /// <summary>
        /// 选中Cid
        /// </summary>
        public int SelectionCid { get; private set; }
        /// <summary>
        /// 追踪标记Cid
        /// </summary>
        public int TracerCid { get; private set; }

        public TbCfgMapUiEntity(ByteBuf _buf)
        {
            //first read common data
            _TbCommonMapUiEntity _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonMapUiEntity(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgMapUiEntity>(size * 3 / 2);
            _dataList = new List<CfgMapUiEntity>(size);

            for (int i = 0; i < size; i++)
            {
                CfgMapUiEntity _v;
                _v = CfgMapUiEntity.DeserializeCfgMapUiEntity(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            PlayerCid = _buf.ReadInt();
            QuestTargetCid = _buf.ReadInt();
            QuestAreaCid = _buf.ReadInt();
            SelectionCid = _buf.ReadInt();
            TracerCid = _buf.ReadInt();

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgMapUiEntity> DataMap => _dataMap;
        public IReadOnlyList<CfgMapUiEntity> DataList => _dataList;

        public CfgMapUiEntity Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgMapUiEntity] config not found,id:" + key.ToString());

            return null;
        }

        public CfgMapUiEntity GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "mapuientity";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgMapUiEntity LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgMapUiEntity(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgMapUiEntity
    {
        private CfgMapUiEntity(ByteBuf _buf, _TbCommonMapUiEntity _commonData)
        {
            Id = _buf.ReadInt();
            Remark = _buf.ReadString();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Describe = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Icon = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Prefab = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Effect = _commonData._field2[dataIndex]; }
            IsShowRotation = _buf.ReadBool();
            IsShowFloor = _buf.ReadBool();
            Updatable = _buf.ReadBool();
            Type = (MapUiEntityType)(_buf.ReadInt());
            MapDisplay = (MapDisplayType)(_buf.ReadInt());
            DynamicLayer = _buf.ReadInt();
            StaticLayer = (StaticLayerType)(_buf.ReadInt());

            PostInit();
        }

        internal static CfgMapUiEntity DeserializeCfgMapUiEntity(ByteBuf _buf, _TbCommonMapUiEntity _commonData)
        {
            return new CfgMapUiEntity(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 策划备注 ---- 编辑器专用
        /// </summary>
        private string Remark { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Describe { get; private set; }
        /// <summary>
        /// 图标
        /// </summary>
        public string Icon { get; private set; }
        /// <summary>
        /// 迷雾预制体
        /// </summary>
        public string Prefab { get; private set; }
        /// <summary>
        /// 特效
        /// </summary>
        public string Effect { get; private set; }
        /// <summary>
        /// 是否旋转
        /// </summary>
        public bool IsShowRotation { get; private set; }
        /// <summary>
        /// 是否显示上下层
        /// </summary>
        public bool IsShowFloor { get; private set; }
        /// <summary>
        /// 是否可移动
        /// </summary>
        public bool Updatable { get; private set; }
        /// <summary>
        /// 类型
        /// </summary>
        public MapUiEntityType Type { get; private set; }
        /// <summary>
        /// 显示区域
        /// </summary>
        public MapDisplayType MapDisplay { get; private set; }
        /// <summary>
        /// 动态层级
        /// </summary>
        public int DynamicLayer { get; private set; }
        /// <summary>
        /// 静态层级
        /// </summary>
        public StaticLayerType StaticLayer { get; private set; }

        /// <summary>
        /// Icon资源全路径
        /// </summary>
        public string Icon_fullPath => $"Res/05_Images/Sprite/{Icon}";
        /// <summary>
        /// Effect资源全路径
        /// </summary>
        public string Effect_fullPath => $"Res/14_Effect/Prefab/{Effect}.prefab";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonMapUiEntity
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal _TbCommonMapUiEntity(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
